package cj.web.vote.dao;
import java.util.Date;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.vote.domain.VoteLog;

/**
 * 
 * @author 
 *
 */
@DAO
public interface VoteLogDAO{
	
	@SQL("SELECT * FROM VoteLog WHERE 1=1 "
	    	    				    		        	+ " AND wxOpenid=:t.wxOpenid,"
	        			    		        	+ " AND wxCity=:t.wxCity,"
	        			    		        	+ " AND wxCountry=:t.wxCountry,"
	        			    		        	+ " AND wxHeadimgurl=:t.wxHeadimgurl,"
	        			    		        	+ " AND wxNickname=:t.wxNickname,"
	        			    		        	+ " AND wxProvince=:t.wxProvince,"
	        			    		        	+ " AND wxSex=:t.wxSex,"
	        			    		        	+ " AND wxUnionid=:t.wxUnionid,"
	        			    		        	+ " AND voteId=:t.voteId,"
	        			    		        	+ " AND voteSongID=:t.voteSongID,"
	        			    		        	+ " AND createAT=:t.createAT,"
	        			    		        	+ " AND updateAT=:t.updateAT"
	        				+" ORDER BY update_date DESC LIMIT :t.start,:t.end ")
    List<VoteLog> query(@SQLParam("t") VoteLog voteLog);
    
    @SQL("select * from VoteLog where id=:1")
    VoteLog queryById(int id);
    
    @SQL("select * from VoteLog where wxOpenid = :1 AND voteId = :2")
    VoteLog queryByOpenIdAndVoteId(String openId,int voteId);
    
    @SQL("select max(id) from VoteLog")
    int queryMaxId(); 
    
    @SQL("INSERT INTO VoteLog ("
    		        		+ "id,"
			        		+ "wxOpenid,"
			        		+ "wxCity,"
			        		+ "wxCountry,"
			        		+ "wxHeadimgurl,"
			        		+ "wxNickname,"
			        		+ "wxProvince,"
			        		+ "wxSex,"
			        		+ "wxUnionid,"
			        		+ "voteId,"
			        		+ "voteSongID,"
			        		+ "createAT,"
			        		+ "updateAT"
							+") VALUES ("
							+ ":t.id,"
							+ ":t.wxOpenid,"
							+ ":t.wxCity,"
							+ ":t.wxCountry,"
							+ ":t.wxHeadimgurl,"
							+ ":t.wxNickname,"
							+ ":t.wxProvince,"
							+ ":t.wxSex,"
							+ ":t.wxUnionid,"
							+ ":t.voteId,"
							+ ":t.voteSongID,"
							+ ":t.createAT,"
							+ ":t.updateAT"
					+")")
    void create(@SQLParam("t") VoteLog voteLog);
	
	@SQL("UPDATE VoteLog SET voteSongId=:1, updateAT=:2 WHERE id=:3")
    void update(int voteSongId,Date updateAT,int voteLogId) ;
    
    @SQL("UPDATE VoteLog SET deleteFlag=0 WHERE id=:id")
    void deleteById(String id);
}